<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: router.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

/*
 * Function to convert a system URL to a SEF URL
 */
function JoomgpstracksBuildRoute(&$query) {

	$segments = array();
	
	$menu = &JSite::getMenu();
	if (empty($query['Itemid'])) {
		$menuItem = &$menu->getActive();
	} else {
		$menuItem = &$menu->getItem($query['Itemid']);
	}
	
	if (isset($query['view'])){
		$segments[] = $query['view'];
		unset($query['view']);
	}
	if (isset($query['layout'])){
		$segments[] = $query['layout'];
		unset($query['layout']);
	}
	if (isset($query['id'])){
		$segments[] = $query['id'];
		unset($query['id']);	
	}
        if (isset($query['controller'])) {
                $segments[] = $query['controller'];
                unset($query['controller']);
        }
        if (isset($query['task'])) {
                $segments[] = $query['task'];
                unset($query['task']);
        }
        if (isset($query['search'])) {
                $segments[] = $query['search'];
                unset($query['search']);
        }
        if (isset($query['rate'])) {
                $segments[] = $query['rate'];
                unset($query['rate']);
        }
	
	return $segments;
}
/*
 * Function to convert a SEF URL back to a system URL
 */
function JoomgpstracksParseRoute($segments) {

	$vars = array();

	//Get the active menu item
	$menu =& JSite::getMenu();
	$item =& $menu->getActive();

	// Count route segments
	$count = count($segments);

        switch($segments[1])  {

            case 'list':
                $vars['view'] = 'tracks';
                $vars['layout'] = 'list';
                $vars['search'] = $segments[2];
                break;

            case 'track':
                $vars['view'] = 'tracks';
                $vars['layout'] = 'track';
                $vars['id'] = $segments[2];
                break;

            case 'form':
                $vars['view'] = 'tracks';
                $vars['layout'] = 'form';
                $vars['id'] = $segments[2];
                break;

            case 'user':
                $vars['view'] = 'tracks';
                $vars['layout'] = 'user';
                break;

            case 'tracks':
                $vars['controller'] = 'tracks';
                $vars['task'] = 'delete';
                $vars['id'] = $segments[0];
                break;

            case 'default':
                $vars['view'] = 'cats';
                $vars['layout'] = 'default';
                break;

            case 'vote':
//                $vars['controller'] = 'tracks';
                $vars['task'] = 'vote';
                $vars['id'] = $segment[1];
                $vars['rate'] = $segment[1];
                break;
        }

       return $vars;

}
?>